import React, { useEffect, useState } from "react";
import { View, Text, Button } from '@tarojs/components'
import Taro from '@tarojs/taro'
import './products.less'


export default () => {
  const [data, setData]: any = useState({
    name: ''
  })
  useEffect(() => {
    const q = Taro.getCurrentInstance().router?.params
    console.log(q)
    const id = q?.id
    if(!id){
      return
    }

    Taro.request({
      url: `${process.env.PREFIX}/product/detail/${id}`,
    }).then(r => {
      setData(r.data.data)
    })
  }, [])

  const buy = ()=>{
    Taro.navigateTo({
      url: `/pages/mall/orderConfirm?productId=${data.id}`
    })
  }

  return (
    <View>
      <View>轮播图</View>
      <View>{data.name}</View>
      <View>[tags]</View>
      <View className='flex-row'>
        <View>{data.price}金币 <Text>原价: 98元</Text></View>
        <View><Button>分享好友</Button></View>
      </View>
      <View>[vip]</View>
      <View>[tag1][tag2]</View>
      <View>
        [商品详情]
      </View>
      <View><Button onClick={buy}>立即兑换</Button></View>
    </View>
  )
}

